﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AudioController : MonoBehaviour {

	private static AudioController instance;
	private static AudioController GetInstance() {
		return instance;
	}
	
	void Awake () {
		if (instance != null && instance != this){
			Destroy(this.gameObject);
			return;
		} else {
			instance = this;
		}
		DontDestroyOnLoad (transform.gameObject);
	}

	Dictionary<string, AudioSource> sounds;
	public static AudioController audio_controller;

	// Use this for initialization
	void Start () {
		sounds = new Dictionary<string, AudioSource>();
		audio_controller = GetComponent<AudioController>();
		LoadSounds();
	}

	void LoadSounds(){
		foreach(AudioSource sound in GetComponents<AudioSource>()){
			sounds.Add(sound.clip.name, sound);
		}
	}

	public AudioSource GetSound(string name){
		return sounds[name];
	}

	public void StopAllSounds(){
		foreach(AudioSource sound in GetComponents<AudioSource>()){
			sound.Stop();
		}
	}
}
